
//
//  HMStatusRetweetedFrame.m
//  黑马微博-wzy
//
//  Created by Mac on 2017/2/14.
//  Copyright © 2017年 Mac. All rights reserved.
//

#import "HMStatusRetweetedFrame.h"
#import "HMStatus.h"
#import "HMUser.h"
#import "HMStatusPhotosView.h"


@implementation HMStatusRetweetedFrame

//根据传进来的转发微博数据,计算准发微博的frame
//重写 retweetedStatus
- (void)setRetweetedStatus:(HMStatus *)retweetedStatus{
    _retweetedStatus = retweetedStatus;
    
    //1.昵称
    CGFloat nameX = HMStatusCellInset;
    CGFloat nameY = HMStatusCellInset;
    
    
    NSString *str = [NSString stringWithFormat:@"@%@", retweetedStatus.user.name];
    CGSize nameSize = [str sizeWithAttributes:@{NSFontAttributeName:HMStatusRetweetedNameFont}];
    self.nameFrame = (CGRect){{nameX, nameY}, nameSize};
    
    //2.正文
    CGFloat textX = nameX;
    CGFloat textY = CGRectGetMaxY(self.nameFrame) + HMStatusCellInset * 0.5;
    CGFloat maxW = kScreenWidth - 2 * textX;
    CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
    CGSize textSize = [retweetedStatus.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:HMStatusOriginalTextFont} context:nil].size;
    self.textFrame = (CGRect){{textX, textY}, textSize};
    
    
    //3.配图相册
    CGFloat h = 0;
    if (retweetedStatus.pic_urls.count) {
        CGFloat photosX = textX;
        CGFloat photosY = CGRectGetMaxY(self.textFrame) + HMStatusCellInset;
        CGSize photosSize = [HMStatusPhotosView sizeWithPhotosCount:(int)retweetedStatus.pic_urls.count];
        
        self.photosFrame = (CGRect){{photosX, photosY}, photosSize};
        
        h = CGRectGetMaxY(self.photosFrame) + HMStatusCellInset;
        
    }else{
        h = CGRectGetMaxY(self.textFrame) + HMStatusCellInset;
    }
    
    //4.自己frame
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = kScreenWidth;
    
    self.retweetedF = CGRectMake(x, y, w, h);
}





@end
